/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlysieuthi;

import DTO.CChiTietHoaDon;
import DTO.CKho;
import Model.CReport;
import java.beans.PropertyVetoException;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.omg.CORBA.TIMEOUT;


/**
 *
 * @author quangphuc
 */
public class FrmReport extends javax.swing.JFrame {

    /**
     * Creates new form FrmReport
     */
    private FrmReport() {
        initComponents();
        setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
    }

    class CallReport implements Runnable{
        String title ="";
        Timestamp begin;
        Timestamp end;
        CKho kho = null;
        String fileName = "";
        String theo ="";//theo thang, theo quy,theo nam
        public CallReport(Timestamp begin,Timestamp end,CKho kho,String loai_phieu
                ,String fileName,String title,String theo){
            this.begin = begin;
            this.end = end;
            this.kho = kho;
            this.title = title;
            this.fileName = fileName;
            this.theo = theo;
        }         
        JRBeanCollectionDataSource collecDataSource;
        HashMap parameters ;
        public CallReport(JRBeanCollectionDataSource collectionDataSource,String fileName,HashMap parameters){
            this.collecDataSource = collectionDataSource;
            this.fileName = fileName;
            this.parameters = parameters;
        }
        @Override
        public void run() {
            try {
                /*
                List<CChiTietHoaDon> list = new ArrayList<CChiTietHoaDon>();
                if(kho == null){
                    System.out.println("kho co gia tri null");
                    return;
                }
                String diachi = "Địa chỉ :" + kho.getDiaChi();
                String dienthoai = "Điện thoại :" + kho.getDienThoai();
                String fax = "Fax :" + kho.getFax();
                System.out.println("dia chi : " + kho.getDiaChi());
                long kho_id = kho.getId();
                CReport _report = new CReport();
                list = _report.getChiTietHoaDon(this.begin, this.end, kho_id, "HDBH");
                HashMap parameters = new HashMap();
                parameters.put("title", title);
                parameters.put("p_diachi", diachi);
                parameters.put("p_dienthoai", dienthoai);
                parameters.put("fax", fax);//
                parameters.put("p_theo", this.theo);//"src/report/baocaoloinhuan.jrxml"
                JRBeanCollectionDataSource collectionDataSource = new JRBeanCollectionDataSource(list);
                */
                SubReport myiReportViewer = new SubReport(this.fileName, this.collecDataSource,this.parameters);
                myiReportViewer.setBounds(0, 0, desktopPane.getWidth(), desktopPane.getHeight());
                myiReportViewer.setVisible(true);
                desktopPane.add(myiReportViewer);
                myiReportViewer.setSelected(true);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(FrmReport.class.getName()).log(Level.SEVERE, null, ex);
            } 
        }                
    }
    
    public FrmReport(JRBeanCollectionDataSource collectionDataSource,String fileName,HashMap parameters){
        this();        
         Thread t = new Thread(new CallReport(collectionDataSource, fileName, parameters));
         t.start();
    }
    
    public FrmReport(Timestamp begin,Timestamp end,CKho kho,String loai_phieu,String fileName,String title,String theo){
        this();        
        Thread t = new Thread(new CallReport(begin, end, kho, loai_phieu, fileName, title,theo));
        t.start();      
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();

        javax.swing.GroupLayout desktopPaneLayout = new javax.swing.GroupLayout(desktopPane);
        desktopPane.setLayout(desktopPaneLayout);
        desktopPaneLayout.setHorizontalGroup(
            desktopPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 784, Short.MAX_VALUE)
        );
        desktopPaneLayout.setVerticalGroup(
            desktopPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 538, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmReport.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmReport.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmReport.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmReport.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmReport().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane desktopPane;
    // End of variables declaration//GEN-END:variables
}
